//题目链接：https://www.lanqiao.cn/problems/1030/learning/
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    // 请在此输入您的代码
    string s1, s2;
    cin >> s1 >> s2;
    string a[1001], b[1001];
    int n = 0;
    // 学会这种提取字符串的方法，特别巧妙
    for (int i = 0;i < s1.length();)
    {
        n++;
        if (s1[i] >= 'A' && s1[i] <= 'Z')
        {
            a[n] += s1[i++];
        }
        while (s1[i] >= 'a' && s1[i] <= 'z')
        {
            a[n] += s1[i++];
        }
    }

    int m = 0;
    for (int i = 0;i < s2.length();)
    {
        m++;
        if (s2[i] >= 'A' && s2[i] <= 'Z')
        {
            b[m] += s2[i++];
        }
        while (s2[i] >= 'a' && s2[i] <= 'z')
        {
            b[m] += s2[i++];
        }
    }
    //按照最长公共子序列的模板来写
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 1;i <= n;i++)
    {
        for (int j = 1;j <= m;j++)
        {
            if (a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}